******SET YOUR DIRECTORY to ...\replication



clear all
set more off


///////////////////////////////////////////////////////////////
///TABLE A.1///////////////////////////////////////////////////
///////////////////////////////////////////////////////////////


use "finaldata\final_cc_data.dta", clear

g treat = (ph1_plc_wtm_wtm_0_r>=6.8 & ph1_plc_wtm_wtm_0_r<=7.7)

drop if fipsplace_00==.
xtset fipsplace_00 year

drop if year>1991

***Merge with employment decentralization
merge 1:1 fipsplace_00 year using "finaldata\data_cbp.dta"
drop _merge

drop if fipsplace_00==.
xtset fipsplace_00 year

*Generate variables
gen prop_cc=tot_cc_oripop_corr/(tot_cc_oripop_corr+tot_ncc_oripop_corr)
gen pop_msa=tot_cc_oripop_corr+tot_ncc_oripop_corr
forval i=1(1)26 {
g rate_cc_crime`i' = totnpcc_cc_offenses_`i'c * 1000
}
g rate_cc_vc =  totnpcc_cc_offenses_vc *  1000
g rate_cc_aggass =  (totnpcc_cc_offenses_vc - totnpcc_cc_offenses_1c - totnpcc_cc_offenses_3c - totnpcc_cc_offenses_6c) *  1000
replace rate_cc_aggass=0 if rate_cc_aggass<0
gen year_91=(year==1991)
gen year_90=(year==1990)

replace tetraethyl=(tetraethyl*0.90)/1000

replace tot_cc_oripop_corr=tot_cc_oripop_corr/1000
replace tot_ncc_oripop_corr=tot_ncc_oripop_corr/1000
replace pop_msa=pop_msa/1000

gen emp_ctycc_sic0=perc_empl_ctycc_sic0*emp_msa_sic0
gen emp_ctyncc_sic0=emp_msa_sic0-emp_ctycc_sic0
replace emp_ctycc_sic0=emp_ctycc_sic/1000
replace emp_ctyncc_sic0=emp_ctyncc_sic0/1000
replace emp_msa_sic0=emp_msa_sic0/1000


file open myfile using table_sumstat.txt, write replace
file write myfile "\begin{tabular}{l c c c c c} \hline\hline \textbf{Variable} & \textbf{Mean} &  \textbf{s.e.} & \textbf{Min} & \textbf{Max} & \textbf{Change}  \\  \hline" _n

local varlist  "tot_cc_oripop_corr tot_ncc_oripop_corr prop_cc pop_msa emp_ctycc_sic0 emp_ctyncc_sic0 perc_empl_ctycc_sic0 emp_msa_sic0 ph1_plc_wtm_wtm_0_r ph_ncc tetraethyl rate_cc_vc rate_cc_crime1 rate_cc_crime3 rate_cc_crime6 rate_cc_aggass rate_cc_crime17 rate_cc_crime21 rate_cc_crime22 rate_cc_crime26"
foreach var in `varlist'{

 
if "`var'"=="tot_cc_oripop_corr"{
 local name = "Pop. CC (in 1,000) (60-91)"
 local fixed = 0
 local minyear=1960
 local maxyear=1991
 }
     else if "`var'"=="tot_ncc_oripop_corr"{
 local name = "Pop. NCC (in 1,000) (60-91)"
 local fixed = 0
 local minyear=1960
 local maxyear=1991
 }
    else if "`var'"=="prop_cc"{
 local name = "Prop. Pop. CC (60-91)"
 local fixed = 0
 local minyear=1960
 local maxyear=1991
 }
   else if "`var'"=="pop_msa"{
 local name = "Pop. MSA (in 1,000) (60-91)"
 local fixed = 0
 local minyear=1960
 local maxyear=1991
 }
    else if "`var'"=="emp_ctycc_sic0"{
 local name = "Empl. CC (in 1,000) (74-91)"
 local fixed = 0
 local minyear=1974
 local maxyear=1991
 }
    else if "`var'"=="emp_ctyncc_sic0"{
 local name = "Empl. NCC (in 1,000) (74-91)"
 local fixed = 0
 local minyear=1974
 local maxyear=1991
 }
    else if "`var'"=="perc_empl_ctycc_sic0"{
 local name = "Prop. Empl. CC (74-91)"
 local fixed = 0
 local minyear=1974
 local maxyear=1991
 }
    else if "`var'"=="emp_msa_sic0"{
 local name = "Empl. MSA (in 1,000) (74-91)"
 local fixed = 0
 local minyear=1974
 local maxyear=1991
 }
     else if "`var'"=="ph1_plc_wtm_wtm_0_r"{
 local name = "pH CC"
 local fixed = 1
 }
      else if "`var'"=="ph_ncc"{
 local name = "pH NCC"
 local fixed = 1
 }
     else if "`var'"=="tetraethyl"{
 local name = "Tetraethyl Lead (in kilotonne) (60-91)"
 local fixed = 0
 local minyear=1960
 local maxyear=1991
 }
           else if "`var'"=="rate_cc_vc"{
 local name = "Violent Crime Rate CC (per 1,000) (60-91)"
 local fixed = 0
 local minyear=1960
 local maxyear=1991
 }
         else if "`var'"=="rate_cc_crime1"{
 local name = "Murder Rate CC (per 1,000) (60-91)"
 local fixed = 0
 local minyear=1960
 local maxyear=1991
 }
          else if "`var'"=="rate_cc_crime3"{
 local name = "Rape Rate CC (per 1,000) (60-91)"
 local fixed = 0
 local minyear=1960
 local maxyear=1991
 }
           else if "`var'"=="rate_cc_crime6"{
 local name = "Robbery Rate CC (per 1,000) (60-91)"
 local fixed = 0
 local minyear=1960
 local maxyear=1991
 }
            else if "`var'"=="rate_cc_aggass"{
 local name = "Agg. Assault Rate CC (per 1,000) (60-91)"
 local fixed = 0
 local minyear=1960
 local maxyear=1991
 }
            else if "`var'"=="rate_cc_crime17"{
 local name = "Burglary Rate CC (per 1,000) (60-91)"
 local fixed = 0
 local minyear=1960
 local maxyear=1991
 }
             else if "`var'"=="rate_cc_crime21"{
 local name = "Larceny Rate CC (per 1,000) (60-91)"
 local fixed = 0
 local minyear=1960
 local maxyear=1991
 }
              else if "`var'"=="rate_cc_crime22"{
 local name = "Vehicle Theft Rate CC (per 1,000) (60-91)"
 local fixed = 0
 local minyear=1960
 local maxyear=1991
 }
               else if "`var'"=="rate_cc_crime26"{
 local name = "Total crimes CC (per 1,000) (60-91)"
 local fixed = 0
 local minyear=1960
 local maxyear=1991
 }
 else {
 local name = "ERROR"
 }

 su `var' 
 local mmean = r(mean)
 local ssd = trim("`: display %8.2f r(sd)'")
 local mmin = trim("`: display %8.2f r(min)'")
 local mmax = trim("`: display %8.2f r(max)'")
 
 if `fixed'==0 & `minyear'==1960 & `maxyear'==1991{
	xtreg `var' year_91 if year==1960 | year==1991, fe vce(conventional)
	local dd = _b[year_91]
	local pval = ttail(e(df_r),abs(_b[year_91]/_se[year_91]))*2
	 if `pval'>0.1  {
		local dd = string(`dd',"%8.2f") 
	 } 
	 else if `pval'>0.05 { 
		local dd = string(`dd',"%8.2f") + "$^\star$"
	 }
	  else if `pval'>0.01 { 
		local dd = string(`dd',"%8.2f") + "$^\star$" + "$^\star$"
	 }
	 else {
		local dd = string(`dd',"%8.2f") + "$^\star$" + "$^\star$" + "$^\star$"
	 }
	 }
	 
	if `fixed'==0 & `minyear'==1960 & `maxyear'==1990{
	xtreg `var' year_90 if year==1960 | year==1990, fe vce(conventional)
	local dd = _b[year_90]
	local pval = ttail(e(df_r),abs(_b[year_90]/_se[year_90]))*2
	 if `pval'>0.1  {
		local dd = string(`dd',"%8.2f") 
	 } 
	 else if `pval'>0.05 { 
		local dd = string(`dd',"%8.2f") + "$^\star$"
	 }
	  else if `pval'>0.01 { 
		local dd = string(`dd',"%8.2f") + "$^\star$" + "$^\star$"
	 }
	 else {
		local dd = string(`dd',"%8.2f") + "$^\star$" + "$^\star$" + "$^\star$"
	 }
	 }
	 
	 
	if `fixed'==0 & `minyear'==1974 & `maxyear'==1991{
	xtreg `var' year_91 if year==1974 | year==1991, fe vce(conventional)
	local dd = _b[year_91]
	local pval = ttail(e(df_r),abs(_b[year_91]/_se[year_91]))*2
	 if `pval'>0.1  {
		local dd = string(`dd',"%8.2f") 
	 } 
	 else if `pval'>0.05 { 
		local dd = string(`dd',"%8.2f") + "$^\star$"
	 }
	  else if `pval'>0.01 { 
		local dd = string(`dd',"%8.2f") + "$^\star$" + "$^\star$"
	 }
	 else {
		local dd = string(`dd',"%8.2f") + "$^\star$" + "$^\star$" + "$^\star$"
	 }
	 }
	 
	 
	 if `fixed' ==1 {
		local dd = "."
	 }
 
 
  file write myfile ("`name'") _tab "&" %8.2f (`mmean') _tab "&"   _tab %8.2f ("`ssd'") _tab "&" _tab %8.2f ("`mmin'") _tab "&" _tab %8.2f ("`mmax'") _tab "&" _tab %8.2f ("`dd'") _tab "\\" _n 
 
 } 
*

file write myfile "\hline \end{tabular}"
file close myfile








///////////////////////////////////////////////////////////////
///FIGURE A.1///////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
use "finaldata\final_cc_data.dta", clear

drop if fipsplace_00==.
xtset fipsplace_00 year

drop if year>1991
drop if year<1960

egen vcn_cc_us=total( totn_cc_offenses_vc),by(year)
egen vcn_ncc_us=total( totn_ncc_offenses_vc),by(year)
egen pop_cc_us=total(tot_cc_oripop_corr),by(year)
egen pop_ncc_us=total(tot_ncc_oripop_corr),by(year)
gen vcnpcc_cc_us=1000*vcn_cc_us/pop_cc_us
gen vcnpcc_ncc_us=1000*vcn_ncc_us/pop_ncc_us
gen perc_cc_us=pop_cc_us/(pop_cc_us+pop_ncc_us)
replace pop_cc_us= pop_cc_us/1000000
replace pop_ncc_us= pop_ncc_us/1000000

label var perc_cc_us "Share Pop CC"
label var vcnpcc_cc_us "Violent crime in CC"
label var vcnpcc_ncc_us "Violent crime in NCC"
label var pop_cc_us "Population in CC (million)"
label var pop_ncc_us "Population in NCC (million)"

sum perc_cc_us if year==1960
sum perc_cc_us if year==1990
sum vcnpcc_cc_us if year==1960
sum vcnpcc_cc_us if year==1991
sum vcnpcc_ncc_us if year==1960
sum vcnpcc_ncc_us if year==1991
sum vcn_cc_us if year==1960
sum vcn_cc_us if year==1991
sum vcn_ncc_us if year==1960
sum vcn_ncc_us if year==1991
sum pop_cc_us if year==1960
sum pop_cc_us if year==1991
sum pop_ncc_us if year==1960
sum pop_ncc_us if year==1991

///TS VC and suburbanization and population CC vs NCC
sort year

twoway (line perc_cc_us year, yaxis(1) legend(symxsize(5))) (line vcnpcc_cc_us vcnpcc_ncc_us year, yaxis(2) ytitle("Violent crime per 1,000 inhab.", axis(2)) legend(symxsize(5)))

///Scatter change VC and change suburbanization
gen perc_cc=tot_cc_oripop_corr/(tot_cc_oripop_corr+tot_ncc_oripop_corr)

foreach var of varlist perc_cc totnpcc_cc_offenses_vc{
gen `var'_1961_2=`var' if year==1961
egen `var'_1961=max(`var'_1961_2),by(fipsplace_00)
gen `var'_1991_2=`var' if year==1991
egen `var'_1991=max(`var'_1991_2),by(fipsplace_00)
gen d`var'=`var'_1991-`var'_1961
}
label var dperc_cc "Change Sh Pop CC 61-91"
label var dtotnpcc_cc_offenses_vc "Change violent crime 61-91"

gen MSA_name="Atlanta, GA" if FMSA==520
replace MSA_name="Boston, MA" if FMSA==1120
replace MSA_name="Chicago, IL" if FMSA==1600
*replace MSA_name="Dallas, TX" if FMSA==1920
replace MSA_name="Houston, TX" if FMSA==3360
replace MSA_name="Miami, FL" if FMSA==5000
replace MSA_name="New York, NY" if FMSA==5600
replace MSA_name="Los Angeles, LA" if FMSA==4480
replace MSA_name="Philadelphia, PA" if FMSA==6160
replace MSA_name="Washington, DC" if FMSA==8840

graph twoway (scatter dperc_cc dtotnpcc_cc_offenses_vc if dtotnpcc_cc_offenses_vc<0.05, mlabel(MSA_name) mlabcolor(red)) (lfit dperc_cc dtotnpcc_cc_offenses_vc if dtotnpcc_cc_offenses_vc<0.05, legend(symxsize(5)))





///////////////////////////////////////////////////////////////
///TABLE A.2///////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
use "finaldata\final_cc_data.dta", clear

drop if fipsplace_00==.

merge 1:1 fipsplace_00 year using "finaldata\data_cbp_msa.dta"

set matsize  700

xtset fipsplace_00 year

gen emp_ctyncc_sic0=emp_msa_sic0-emp_ctycc_sic0

gen vc_pc=totnpcc_cc_offenses_vc*1000
gen vc_ncc_pc=totnpcc_ncc_offenses_vc*1000

drop if tot_ncc_oripop_corr == .


file open myfile using "summary_main.tex", write replace

file write myfile " \begin{tabular}{lcccccc} \hline"
file write myfile "     &\multicolumn{1}{c}{1960}&\multicolumn{1}{c}{1970}&\multicolumn{1}{c}{1980}&\multicolumn{1}{c}{1990}\\ \hline " _n


local i = 0
forval yy = 1960(10)1990 {
	local i = `i' + 1
	su tot_cc_oripop_corr if year == `yy'
	local aa`i' = string(r(mean),"%9.0f") 
}

file write myfile " Residential Population CC (place)		&     `aa1'	&  `aa2'  &  `aa3' & `aa4' & `aa5'  \\ " _n



local i = 0
forval yy = 1960(10)1990 {
	local i = `i' + 1
	su tot_ncc_oripop_corr if year == `yy'
	local aa`i' = string(r(mean),"%9.0f") 
}

file write myfile "  Residential Population NCC (place)		&     `aa1'	&  `aa2'  &  `aa3' & `aa4' & `aa5'  \\ " _n


local i = 0
forval yy = 1960(10)1990 {
	local i = `i' + 1
	su emp_ctycc_sic0 if year == `yy'
	local aa`i' = string(r(mean),"%9.0f") 
}

file write myfile "Employment CC (county)		&    	&   &  `aa3' & `aa4' & `aa5'  \\ " _n



local i = 0
forval yy = 1960(10)1990 {
	local i = `i' + 1
	su emp_ctyncc_sic0 if year == `yy' 
	local aa`i' = string(r(mean),"%9.0f") 
}

file write myfile "Employment NCC (county)		&    	&   &  `aa3' & `aa4' & `aa5'  \\ " _n


local i = 0
forval yy = 1960(10)1990 {
	local i = `i' + 1
	su vc_pc if year == `yy' 
	local aa`i' = string(r(mean),"%9.2f") 
}

file write myfile "Violent crime per 1,000 inhab. CC (place)		&    `aa1'	&  `aa2'   &  `aa3' & `aa4' & `aa5'  \\ " _n



local i = 0
forval yy = 1960(10)1990 {
	local i = `i' + 1
	su vc_ncc_pc if year == `yy' 
	local aa`i' = string(r(mean),"%9.2f") 
}

file write myfile "Violent crime per 1,000 inhab. NCC (place)		&    	`aa1'	&  `aa2'  &  `aa3' & `aa4' & `aa5'  \\ " _n


file write myfile " \end{tabular}"
file close myfile






///////////////////////////////////////
///FIGURE A.2//////////////////////////
///////////////////////////////////////

use "finaldata\final_cc_data.dta", clear

drop if fipsplace_00==.
xtset fipsplace_00 year


gen vc_pc=totnpcc_cc_offenses_vc*1000

g good_soil = (ph1_plc_wtm_wtm_0_r>=6.8 & ph1_plc_wtm_wtm_0_r<=7.7)

*drop if year>1991
//
egen vcn_cc_us=total( totn_cc_offenses_vc),by(year good_soil)
egen pop_cc_us=total(tot_cc_oripop_corr),by(year good_soil)
gen vcnpcc_cc_us=(vcn_cc_us/pop_cc_us)*1000

egen vcnpcc_cc_us1 = mean(vc_pc), by(year good_soil)

label var vcnpcc_cc_us1 "Violent Crime Rate in CC"

drop if year<1960
sort year

twoway (line vcnpcc_cc_us1 year if year>=1960 & good_soil==1, xlabel(1960(10)2010) ylabel(0(5)15) yscale(range(0 15) axis(1)) ) (line vcnpcc_cc_us1 year if year>=1960 & good_soil==0), legend(order(1 "Low LB" 2 "High LB"))





///////////////////////////////////////
///FIGURE A.3//////////////////////////
///////////////////////////////////////

/////GIS

***Open Shapefile with region census divisions (rawdata\tigerdivisions)

***Open Shapefile with places (intermediatedata\tl_2010_allstates_place00_naec.shp)

***Create shapefile with centroid of places

***Link centroid of place to final_cc_data.txt

***Create color labels for different levels of variable ph1_plc_wtm_wtm_0_r

///////////////////////////////////////////////////////////////
///TABLE A.3///////////////////////////////////////////////////
///////////////////////////////////////////////////////////////

use "finaldata\final_cc_data.dta", clear

g treat_good = (ph1_plc_wtm_wtm_0_r>=6.8 & ph1_plc_wtm_wtm_0_r<=7.7)
g treat = 1-treat

drop if fipsplace_00==.
xtset fipsplace_00 year

g share_cc = cpop / pop
local varlist =  "emp empag empbus empcon emped empfire empgov empman empmin emppro"
foreach var in `varlist'{
g `var'_rate = (`var' / pop) * 100
}

*

forval i=1(1)26 {
g rate_cc_crime`i' =  totnpcc_cc_offenses_`i'c * 10000
}
g rate_cc_vc =  totnpcc_cc_offenses_vc *  10000
g rate_cc_aggass =  (totnpcc_cc_offenses_vc - totnpcc_cc_offenses_1c - totnpcc_cc_offenses_3c - totnpcc_cc_offenses_6c) *  10000


g dens_cc=cpop/carea


g labor_rate =   labfor / pop
g over25_rate = over25 / pop

file open myfile using table_a3.txt, write replace
file write myfile "\begin{tabular}{l c cc c cc} \hline\hline \textbf{Variable} & \textbf{Average} &  \multicolumn{2}{c}{\textbf{Levels}} & & \multicolumn{2}{c}{\textbf{Trends}} \\ \cline{3-4} \cline{6-7} \\  &  & \textbf{All US} & \textbf{Inside Division} & &  \textbf{All US} & \textbf{Inside Division} \\  \hline" _n

local varlist  "carea area share_cc cpop pop dens_cc popdns rate_cc_vc rate_cc_crime1 rate_cc_crime3 rate_cc_crime6 rate_cc_aggass rate_cc_crime17 rate_cc_crime21 rate_cc_crime22 rate_cc_crime26 rent  value cincome income precip sun jantemp jultemp cpctblk  pctblk cpctfst  pctfst  dis_borcoa  unm labor_rate emp_rate empag_rate empbus_rate empcon_rate emped_rate empfire_rate empgov_rate empman_rate empmin_rate emppro_rate  medage pct65up  pctoth  pubtrans  school racc raccld raccya raccy raccyc ray raya rayc rays_planm rays_planc"
foreach var in `varlist'{

 
if "`var'"=="share_cc"{
 local name = "Share Pop. CC (50 - 60)"
 local t1 = 1950
 local t2 = 1960
 local fixed = 0
 }
     else if "`var'"=="carea"{
 local name = "Area CC (50)"
 local t1 = 1950
 local fixed = 1
 }
    else if "`var'"=="area"{
 local name = "Area MSA (50)"
 local t1 = 1950
 local fixed = 1
 }
   else if "`var'"=="cpop"{
 local name = "Population CC (50 - 60)"
 local t1 = 1950
 local t2 = 1960
 local fixed = 0
 }
    else if "`var'"=="pop"{
 local name = "Population MSA (50 - 60)"
 local t1 = 1950
 local t2 = 1960
 local fixed = 0
 }
      else if "`var'"=="dens_cc"{
 local name = "Pop. Density CC (50 - 60)"
 local t1 = 1950
 local t2 = 1960
 local fixed = 0
 }
     else if "`var'"=="popdns"{
 local name = "Pop. Density MSA  (50 - 60)"
 local t1 = 1950
 local t2 = 1960
 local fixed = 0
 }
           else if "`var'"=="rate_cc_vc"{
 local name = "Violent Crime Rate CC (per 10000)  (60 - 63)"
 local t1 = 1960
 local t2 = 1963
 local fixed = 0
 }
         else if "`var'"=="rate_cc_crime1"{
 local name = "Murder Rate CC (per 10000) (60 - 63)"
 local t1 = 1960
 local t2 = 1963
 local fixed = 0
 }
          else if "`var'"=="rate_cc_crime3"{
 local name = "Rape Rate CC (per 10000) (60 - 63)"
 local t1 = 1960
 local t2 = 1963
 local fixed = 0
 }
           else if "`var'"=="rate_cc_crime6"{
 local name = "Robbery Rate CC (per 10000) (60 - 63)"
 local t1 = 1960
 local t2 = 1963
 local fixed = 0
 }
            else if "`var'"=="rate_cc_aggass"{
 local name = "Agg. Assault Rate CC (per 10000) (60 - 63)"
 local t1 = 1960
 local t2 = 1963
 local fixed = 0
 }
            else if "`var'"=="rate_cc_crime17"{
 local name = "Burglary Rate CC (per 10000) (60 - 63)"
 local t1 = 1960
 local t2 = 1963
 local fixed = 0
 }
             else if "`var'"=="rate_cc_crime21"{
 local name = "Larceny Rate CC (per 10000)(60 - 63)"
 local t1 = 1960
 local t2 = 1963
 local fixed = 0
 }
              else if "`var'"=="rate_cc_crime22"{
 local name = "Vehicle Theft Rate CC (per 10000) (60 - 63)"
 local t1 = 1960
 local t2 = 1963
 local fixed = 0
 }
              else if "`var'"=="rate_cc_crime26"{
 local name = "Total Crimes CC (per 10000) (60 - 63)"
 local t1 = 1960
 local t2 = 1963
 local fixed = 0
 }
			  else if "`var'"=="rent"{
 local name = "Median Gross Rent (housing unit) MSA (60)"
 local t1 = 1960
 local fixed = 1
 }
       else if "`var'"=="value"{
 local name = "Median Single Family House Value MSA (60)"
 local t1 = 1960
 local fixed = 1
 }
     else if "`var'"=="cincome"{
 local name = "Median Family Income CC (50-60)"
  local t1 = 1950
 local t2 = 1960
 local fixed = 0
 }
      else if "`var'"=="income"{
 local name = "Median Family Income MSA (50-60)"
  local t1 = 1950
 local t2 = 1960
 local fixed = 0
 }
      else if "`var'"=="precip"{
 local name = "Annual Precipitation (77)"
 local t1 = 1950
 local fixed = 1
 }
       else if "`var'"=="sun"{
 local name = "$\%$ Possible Sun (77)"
 local t1 = 1950
 local fixed = 1
 }
       else if "`var'"=="jantemp"{
 local name = "Average Jan Temp (77)"
 local t1 = 1950
 local fixed = 1
 }
        else if "`var'"=="jultemp"{
 local name = "Average July Temp (77)"
 local t1 = 1950
 local fixed = 1
 }
         else if "`var'"=="cpctblk"{
 local name = "$\%$ Blacks CC (60)"
 local t1 = 1960
 local fixed = 1
 }
          else if "`var'"=="pctblk"{
 local name = "$\%$ Blacks MSA (60)"
 local t1 = 1960
 local fixed = 1
 }
         else if "`var'"=="cpctfst"{
 local name = "$\%$ Foreign CC (60)"
 local t1 = 1960
 local fixed = 1
 }
          else if "`var'"=="pctfst"{
 local name = "$\%$ Foreign MSA (60)"
 local t1 = 1960
 local fixed = 1
 }
          else if "`var'"=="dis_borcoa"{
 local name = "Distance Border or Coast"
 local t1 = 1950
 local fixed = 1
 }
          else if "`var'"=="labor_rate"{
 local name = "Labor Force Civilian MSA (50-60)"
 local t1 = 1950
 local t2 = 1960
 local fixed = 0
 }
           else if "`var'"=="emp_rate"{
 local name = "Emp. Rate MSA (50-60)"
 local t1 = 1950
 local t2 = 1960
 local fixed = 0
 }
            else if "`var'"=="empag_rate"{
 local name = "Emp. Rate Agriculture MSA (50-60)"
  local t1 = 1950
 local t2 = 1960
 local fixed = 0
 }
             else if "`var'"=="empbus_rate"{
 local name = "Emp. Rate Business Services MSA (50)"
 local t1 = 1950
 local t2 = 1960
 local fixed = 1
 }
         else if "`var'"=="empcon_rate"{
 local name = "Emp. Rate Construction MSA (50-60)"
 local t1 = 1950
 local t2 = 1960
 local fixed = 0
 }
       else if "`var'"=="emped_rate"{
 local name = "Emp. Rate Education MSA (60)"
 local t1 = 1960
 local fixed = 1
 }
           else if "`var'"=="empfire_rate"{
 local name = "Emp. Rate Finance MSA (50-60)"
  local t1 = 1950
 local t2 = 1960
 local fixed = 0
 }
            else if "`var'"=="empgov_rate"{
 local name = "Emp. Rate Government MSA (60)"
 local t1 = 1960
 local fixed = 1
 }
              else if "`var'"=="empman_rate"{
 local name = "Emp. Rate Manufacturing MSA (50-60)"
   local t1 = 1950
 local t2 = 1960
 local fixed = 0
 }
              else if "`var'"=="empmin_rate"{
 local name = "Emp. Rate Mining MSA (50)"
   local t1 = 1950
 local t2 = 1960
 local fixed = 1
 }
            else if "`var'"=="emppro_rate"{
 local name = "Emp. Rate Professional MSA (50)"
   local t1 = 1950
 local t2 = 1960
 local fixed = 1
 }
             else if "`var'"=="medage"{
 local name = "Median Age MSA (50-60)"
 local t1 = 1950
 local t2 = 1960
 local fixed = 0
 }
               else if "`var'"=="pct65up"{
 local name = "$\%$ Over 65y MSA (50-60)"
 local t1 = 1950
 local t2 = 1960
 local fixed = 0
 }
                 else if "`var'"=="pctoth"{
 local name = "$\%$ Non-white MSA (50-60)"
 local t1 = 1950
 local t2 = 1960
 local fixed = 0
 }
      else if "`var'"=="pubtrans"{
 local name = "$\%$ Pub. Transportation to Work MSA (60)"
 local t1 = 1960
 local fixed = 1
 }
       else if "`var'"=="school"{
 local name = "Median Years of School MSA (50-60)"
 local t1 = 1950
 local t2 = 1960
 local fixed = 0
 }
        else if "`var'"=="unm"{
 local name = "Unemployment Rate MSA (60)"
 local t1 = 1960
 local fixed = 1
 }
		else if "`var'"=="racc"{
 local name = "CC interstate rays (50-60)"
  local t1 = 1950
 local t2 = 1960
 local fixed = 0
 }
      else if "`var'"=="raccld"{
 local name = "CC total rays (50-60)"
  local t1 = 1950
 local t2 = 1960
 local fixed = 0
 }
      else if "`var'"=="raccya"{
 local name = "2-digit CC rays (50-60)"
  local t1 = 1950
 local t2 = 1960
 local fixed = 0
 }
      else if "`var'"=="raccy"{
 local name = "All interstate CC rays (50-60)"
  local t1 = 1950
 local t2 = 1960
 local fixed = 0
 }
      else if "`var'"=="raccyc"{
 local name = "Federally funded CC rays (50-60)"
  local t1 = 1950
 local t2 = 1960
 local fixed = 0
 }
      else if "`var'"=="ray"{
 local name = "All rays in MSA (50-60)"
  local t1 = 1950
 local t2 = 1960
 local fixed = 0
 }
      else if "`var'"=="raya"{
 local name = "2-digit ray in MSA (50-60)"
  local t1 = 1950
 local t2 = 1960
 local fixed = 0
 }
      else if "`var'"=="rayc"{
 local name = "Federally funded rays in MSA (50-60)"
  local t1 = 1950
 local t2 = 1960
 local fixed = 0
 }
 
        else if "`var'"=="rays_planm"{
 local name = "Rays in plan running through MSA"
 local t1 = 1960
 local fixed = 1
 }
        else if "`var'"=="rays_planc"{
 local name = "Rays in plan running through CC"
 local t1 = 1960
 local fixed = 1
 }
 else {
 local name = "ERROR"
 }

 su `var' if year==`t1'
 local aa = r(mean)
 
 reg `var' 1.treat if year==`t1', robust
 local diff = _b[1.treat]
 local pval = ttail(e(df_r),abs(_b[1.treat]/_se[1.treat]))*2
 if `pval'>0.1  {
	local bb = string(`diff',"%11.2f") 
 } 
 else if `pval'>0.05 { 
	local bb = string(`diff',"%11.2f") + "$^\star$"
 }
  else if `pval'>0.01 { 
	local bb = string(`diff',"%11.2f") + "$^\star$" + "$^\star$"
 }
 else {
 	local bb = string(`diff',"%11.2f") + "$^\star$" + "$^\star$" + "$^\star$"
 }
 
 reg `var'  1.treat i.cdivcode if year==`t1', robust
 local diff = _b[1.treat]
 local pval = ttail(e(df_r),abs(_b[1.treat]/_se[1.treat]))*2
 if `pval'>0.1  {
	local cc = string(`diff',"%8.2f") 
 } 
 else if `pval'>0.05 { 
	local cc = string(`diff',"%8.2f") + "$^\star$"
 }
  else if `pval'>0.01 { 
	local cc = string(`diff',"%8.2f") + "$^\star$" + "$^\star$"
 }
 else {
 	local cc = string(`diff',"%8.2f") + "$^\star$" + "$^\star$" + "$^\star$"
 }
 
 if `fixed'==0 {
	xtreg `var'  ib`t1'.year##1.treat, fe robust
	local diff = _b[`t2'.year#1.treat]
	local pval = ttail(e(df_r),abs(_b[`t2'.year#1.treat]/_se[`t2'.year#1.treat]))*2
	if `pval'>0.1  {
		local dd = string(`diff',"%8.2f") 
	} 
	else if `pval'>0.05 { 
		local dd = string(`diff',"%8.2f") + "$^\star$"
	}
	else if `pval'>0.01 { 
		local dd = string(`diff',"%8.2f") + "$^\star$" + "$^\star$"
	}
	else {
		local dd = string(`diff',"%8.2f") + "$^\star$" + "$^\star$" + "$^\star$"
	}
 }
 else {
	local dd = "."
 }
 
 
  if `fixed'==0 {
	xtreg `var'  ib`t1'.year##1.treat ib`t1'.year##i.cdivcode, fe robust
	local diff = _b[`t2'.year#1.treat]
	local pval = ttail(e(df_r),abs(_b[`t2'.year#1.treat]/_se[`t2'.year#1.treat]))*2
	if `pval'>0.1  {
		local ee = string(`diff',"%8.2f") 
	} 
	else if `pval'>0.05 { 
		local ee = string(`diff',"%8.2f") + "$^\star$"
	}
	else if `pval'>0.01 { 
		local ee = string(`diff',"%8.2f") + "$^\star$" + "$^\star$"
	}
	else {
		local ee = string(`diff',"%8.2f") + "$^\star$" + "$^\star$" + "$^\star$"
	}
 }
 else {
	local ee = "."
 }
 
 
  if `fixed'==0 {
	gen `var'_2=`var' if year==`t1'
	egen `var'_t1=max(`var'_2), by(fipsplace_00)
	drop `var'_2
	gen `var'_2=`var' if year==`t2'
	egen `var'_t2=max(`var'_2), by(fipsplace_00)
	gen d_`var'_t1t2=`var'_t2-`var'_t1
	drop `var'_2

 }
 else {
	gen d_`var'_t1t2 = .
	drop d_`var'_t1t2
 }

 
  file write myfile ("`name'") _tab "&" %11.2f (`aa') _tab "&"   _tab %11.2f ("`bb'") _tab "&" _tab %11.2f ("`cc'") _tab "&" _tab _tab "&" _tab %8.2f ("`dd'") _tab "&" _tab %8.2f ("`ee'") _tab "\\" _n 
 
 } 
*

file write myfile "\hline "

reg treat *_t1 if year==1960, rob
testparm *_t1
local fff = r(F)
 local pval = r(p)
 if `pval'>0.1  {
	local bb = string(`fff',"%11.2f") 
 } 
 else if `pval'>0.05 { 
	local bb = string(`fff',"%11.2f") + "$^\star$"
 }
  else if `pval'>0.01 { 
	local bb = string(`fff',"%11.2f") + "$^\star$" + "$^\star$"
 }
 else {
 	local bb = string(`fff',"%11.2f") + "$^\star$" + "$^\star$" + "$^\star$"
 }

reg treat *_t1 i.cdivcode if year==1960, rob
testparm *_t1
local fff = r(F)
 local pval = r(p)
 if `pval'>0.1  {
	local cc = string(`fff',"%11.2f") 
 } 
 else if `pval'>0.05 { 
	local cc = string(`fff',"%11.2f") + "$^\star$"
 }
  else if `pval'>0.01 { 
	local cc = string(`fff',"%11.2f") + "$^\star$" + "$^\star$"
 }
 else {
 	local cc = string(`fff',"%11.2f") + "$^\star$" + "$^\star$" + "$^\star$"
 }
 
reg treat d_*_t1t2 if year==1960, rob
testparm *_t1t2
local fff = r(F)
 local pval = r(p)
 if `pval'>0.1  {
	local dd = string(`fff',"%11.2f") 
 } 
 else if `pval'>0.05 { 
	local dd = string(`fff',"%11.2f") + "$^\star$"
 }
  else if `pval'>0.01 { 
	local dd = string(`fff',"%11.2f") + "$^\star$" + "$^\star$"
 }
 else {
 	local dd = string(`fff',"%11.2f") + "$^\star$" + "$^\star$" + "$^\star$"
 }
 
reg treat d_*_t1t2 i.cdivcode if year==1960, rob
testparm *_t1t2
local fff = r(F)
 local pval = r(p)
 if `pval'>0.1  {
	local ee = string(`fff',"%11.2f") 
 } 
 else if `pval'>0.05 { 
	local ee = string(`fff',"%11.2f") + "$^\star$"
 }
  else if `pval'>0.01 { 
	local ee = string(`fff',"%11.2f") + "$^\star$" + "$^\star$"
 }
 else {
 	local ee = string(`fff',"%11.2f") + "$^\star$" + "$^\star$" + "$^\star$"
 }

  file write myfile ("F-stat joint significance") _tab "&" %11.2f (".") _tab "&"   _tab %11.2f ("`bb'") _tab "&" _tab %11.2f ("`cc'") _tab "&" _tab _tab "&" _tab %8.2f ("`dd'") _tab "&" _tab %8.2f ("`ee'") _tab "\\" _n 


file write myfile "\hline \end{tabular}"
file close myfile





///////////////////////////////////////
///FIGURE A.4//////////////////////////
///////////////////////////////////////
clear all
set more off

use "finaldata\final_cc_data.dta", clear

set matsize 2000

grstyle init
grstyle set plain
grstyle set color s2

drop if fipsplace_00==.
xtset fipsplace_00 year

egen vcn_cc_us=total( totn_cc_offenses_vc),by(year)
egen vcn_ncc_us=total( totn_ncc_offenses_vc),by(year)
egen pop_cc_us=total(tot_cc_oripop_corr),by(year)
egen pop_ncc_us=total(tot_ncc_oripop_corr),by(year)
gen vcnpcc_cc_us=(vcn_cc_us/pop_cc_us)*1000
gen vcnpcc_ncc_us=(vcn_ncc_us/pop_ncc_us)*1000
gen perc_cc_us=pop_cc_us/(pop_cc_us+pop_ncc_us)
replace pop_cc_us= pop_cc_us/1000000
replace pop_ncc_us= pop_ncc_us/1000000
replace tetraethyl = tetraethyl/1000

label var perc_cc_us "Proportion People in CC"
label var vcnpcc_cc_us "Violent Crime Rate in CC"
label var pop_cc_us "Population in CC (million)"
label var pop_ncc_us "Population in NCC (million)"
label var tetraethyl "Tetraethyl Lead"
label var year_old "Year - Lead"
label var year "Year - Violent crime"

sum perc_cc_us if year==1960
sum perc_cc_us if year==1990
sum vcnpcc_cc_us if year==1960
sum vcnpcc_cc_us if year==1991

drop if year<1960

sort year
graph twoway (line vcnpcc_cc_us year if year>=1960 & year <=2005, xlabel(1960(10)2000) ylabel(0(3)18) xaxis(1) yaxis(1) yscale(range(0) axis(1))) (line tetraethyl year_old if year_old>1941 & year_old<=1986,  xaxis(2) yaxis(2) xlabel(1941(10)1981,axis(2)) lpattern(dash))
